/* Lambdas Calling Global and Member Functions */
#include <iostream>
#include <algorithm>
#include <locale>
#include <string>
#include <vector>

using namespace std;

class Person {
private:
	string name;
public:
	Person(const string &n) : name(n) {
	}

	void print() const {
		cout << name << endl;
	}

	void print2(const string &prefix) const {
		cout << prefix << name << endl;
	}
};

char myToupper(char c)
{
	std::locale loc;
	return std::use_facet<std::ctype<char>>(loc).toupper(c);
}

int main()
{
	string s("Internationalization");
	string sub("Nation");

	// search substring case insensitive
	string::iterator pos;
	pos = search(s.begin(), s.end(),
		sub.begin(), sub.end(),
		[](char c1, char c2) {
			return myToupper(c1) == myToupper(c2);
		});
	if (pos != s.end())
	{
		cout << "\"" << sub << "\" is part of \"" << s << "\"" << endl;
	}

	vector<Person> coll = { Person("Tick"), Person("Trick"), Person("Track") };
	// call member function print() for each person
	for_each(coll.begin(), coll.end(), [](const Person &p) {
		p.print();
	});
	cout << endl;

	// call member function print2() with additional argument for each person
	for_each(coll.begin(), coll.end(), [](const Person &p) {
		p.print2("Person: ");
	});

	return 0;
}